package de.tabuma.ssoclient.logik;

import java.util.*;
import de.tabuma.lib.webservice.client.*;
import de.tabuma.ssoclient.entity.*;

/**
 * @author $Author: alefen $
 * @version $Revision: 1.2 $
 * @since $Date: 2010/01/04 10:30:43 $
 */
public class UserGroupFacade {
    public static String soapUrl = "https://tabumasso.appspot.com/webservice";
    public static int create(UserGroup userGroup, String ssoId) throws Exception {
        String methodName = "UserGroupService_create";
        String soapAction = "UserGroupService_create";

        Class returnType = Integer.class;
        Object params[] = {userGroup, ssoId};

        Integer obj = (Integer) ExecuteMethod.executeMethod(methodName, soapAction, soapUrl, params, returnType, null);
        userGroup.setId(obj.longValue());
        UserGroupHashFacade.put(userGroup, ssoId);
        return obj.intValue();
    }

    public static void update(UserGroup userGroup, String ssoId) throws Exception {
        String methodName = "UserGroupService_update";
        String soapAction = "UserGroupService_update";

        Object params[] = {userGroup, ssoId};
        ExecuteMethod.executeMethod(methodName, soapAction, soapUrl, params, null, null);
        UserGroupHashFacade.put(userGroup, ssoId);
    }

    public static UserGroup get(int id, String ssoId) throws Exception {
        String methodName = "UserGroupService_get";
        String soapAction = "UserGroupService_get";

        Class returnType = UserGroup.class;
        Object params[] = {Integer.valueOf(id), ssoId};

        UserGroup obj = UserGroupHashFacade.get(id, ssoId);
        if(obj==null) {
            obj = (UserGroup) ExecuteMethod.executeMethod(methodName, soapAction, soapUrl, params, returnType, null);
        }
        return obj;
    }

    public static void remove(int id, String ssoId) throws Exception {
        String methodName = "UserGroupService_remove";
        String soapAction = "UserGroupService_remove";

        Object params[] = {Integer.valueOf(id), ssoId};
        ExecuteMethod.executeMethod(methodName, soapAction, soapUrl, params, null, null);
        UserGroupHashFacade.remove(id, ssoId);
    }

    public static List<UserGroup> getList(int groupId, String ssoId) throws Exception {
        String methodName = "UserGroupService_getList";
        String soapAction = "UserGroupService_getList";

        Class returnType = List.class;
        Class returnType1 = UserGroup.class;
        Object params[] = {Integer.valueOf(groupId), ssoId};

        List<UserGroup> obj = UserGroupHashFacade.getList(groupId, ssoId);
        if(obj==null) {
            obj = (List<UserGroup>) ExecuteMethod.executeMethod(methodName, soapAction, soapUrl, params, returnType, returnType1);
            UserGroupHashFacade.setList(obj, groupId, ssoId);
        }
        return obj;
    }
}
